

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '123',
  database : 'haha'
});

connection.connect(function(err) {
  if (err) {
    console.error('error connecting: ' + err.stack);
    return;
  }
  console.log('connected as id ' + connection.threadId);
});

// connection.connect();


// connection.query('SELECT * from mm_user', 
// 	function (error, results, fields) {
//   if (error) throw error;
//   console.log(results);
// });

//connection.end();


/*router.post('/add_book_handler', 
	function(req, res, next) {
	var sql = `insert into mm_books(b_name,b_price) 
	values('${req.body.b_name}',${req.body.b_price})`;	
  // res.render('add_book',{});
	  sqlHandler.update(sql,function (resule) {
	  	res.send("搞完了，去看看吧！");
	  });
});*/
module.exports = {
	update:function(sql,cb){
		// connection.connect();
		connection.query(sql, 
			function (error, results, fields) {
		  if (error) throw error;
		  cb(results);
		});
		// connection.end();

	}
}